<?php

namespace App\Modules\Order\Jobs;

use App\Modules\Order\Models\Order;
use App\Modules\Package\Models\GoodPackage;
use App\Modules\Package\Models\PackageAttrValue;
use App\Modules\Package\Models\PackageSpec;
use Facade\Ignition\Support\Packagist\Package;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\SerializesModels;

class AddSpecJob implements ShouldQueue
{
    use Queueable,SerializesModels;

    public $attrValue;

    public function __construct(PackageAttrValue $attrValue)
    {
        $this->attrValue = $attrValue;
    }

    public function handle()
    {
        GoodPackage::query()
            ->orderBy('id', 'asc')
            ->each(function ($item) {
                PackageSpec::query()->firstOrCreate([
                    "package_id" => $item->id,
                    "attr_value_id" => $this->attrValue->id,
                ], [
                    "sales_volume" => 0,
                    "is_default" => 0,
                    "status" => GoodPackage::STATUS_ON,
                ]);
            });
    }
}
